package com.creali.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.creali.web.domain.User;
import com.creali.web.services.UserServices;

@Controller
@RequestMapping(value="/user")
public class UserController {
	
	@Autowired
	private UserServices userServices;
	
	public void setUserServices(UserServices userServices) {
		this.userServices = userServices;
	}

	public ModelAndView add(HttpServletRequest request,
			HttpServletResponse response, User user) throws Exception {
		this.userServices.saveUser(user);
		return new ModelAndView("redirect:list.htm");
	}

	@RequestMapping(method=RequestMethod.GET)
	public String list(Model model) throws Exception {
		User user=new User();
		user.setAboutYou("happys");
		this.userServices.saveUser(user);
		return "testmvc/createUser";
	}
}
